<?php 
namespace Admin\Controller;
class PictureController extends BaseController{
	function htmlPic(){
		session_start();
		$imageOb= M('image');
		$re = $imageOb->select();
		$articleimageOb = M('article');
		$articleimage = $articleimageOb->select();
		$arr=$_SESSION['file'];
		//var_dump($articleimage);
			var_dump($arr);
	
		$this->assign('re',$re);
		$this->display();
	}
	// 前台页面添加图片
	function pictureadd(){
// 将PREview.php复制出来
			
		$this->display();
	}
//前台页面保存
function pictureadd_save(){
		if($_POST){//保存数据
			$productOb=M('image');
			$cRe=$productOb->create();
			if($cRe){
				$re=$productOb->add();
				if($re){
					//先保存图片
					$uploadOb=new \Think\Upload();
					$uploadOb->mimes=array('image/jpeg','image/png','image/gif');
					$uploadOb->autoSub=false;
					$uploadOb->rootPath="./Public/Uploads/html/";
					$imageArr=$uploadOb->upload();
					$imageInfo="没有选择图片";
					if($imageArr){
						$productimageOb=new \Think\Model('productimage','','DB_CONFIG2');
						//实例化图片类
						$imageOb=new \Think\Image();
						foreach($imageArr as $v){
							$imagename=$v['savename'];
							//生成缩略图
							$imageOb->open("./Public/Uploads/product/".$imagename)
									->thumb(130,130,\Think\Image::IMAGE_THUMB_FILLED)
									->save("./Public/Uploads/product/s_".$imagename);
							$productid=$re;
							//图片保存成功后，把图片名称写入产品图片表
							$imageRe=$productimageOb->data(array('productid'=>$productid,'imagename'=>$imagename))
											->add();
						}
						if($imageRe){
							$imageInfo="图片上传成功";
						}else{
							$imageInfo="图片上传失败";
						}
					}
					$this->success("添加成功，$imageInfo",U("Admin/Product/oper"));
				}else{
					$this->error("添加失败",U('Admin/Product/add'));
				}
				exit();
			}else{
				$info=$productOb->getError();
				$this->assign('info',$info);
				$this->assign('arr',$_POST);
			}
		}
		$this->display();
	}

//图片删除
	function del(){
		$id = $_GET['id'];
		$imageOb =D('image');
		$re = $imageOb->where("id=$id")
					->delete();
			echo $id;
	}
	function xiajia(){
		$id= $_GET['id'];
		$articleOb = M('image');
		$arr= array('status'=>0);
		$re = $articleOb->where("id=$id")
						->data($arr)
						->save();
						echo $id;
		
	}
	function shangjia(){
		$id= $_GET['id'];
		$articleOb = M('image');
		$arr= array('status'=>1);
		$re = $articleOb->where("id=$id")
						->data($arr)
						->save();
					echo $id;
	}
	function productPic(){
		$this->display();	
	}

}